package com.yoomiito.app.ui.anyview.shareview

import android.content.Context
import android.graphics.Bitmap
import android.view.View
import com.alibaba.fastjson.JSONObject
import com.yoomiito.app.utils.L
import io.reactivex.Observable
import io.reactivex.android.schedulers.AndroidSchedulers
import java.util.*

class ShareViewManager {

    companion object {
        const val MeiTuan = 1
        val instance by lazy(mode = LazyThreadSafetyMode.SYNCHRONIZED) { ShareViewManager() }
    }

    var onPicMakeListener: (View, Bitmap) -> Unit = {view, bitmap ->  }
    private lateinit var shareView: BaseShareView

    /**
     * data根据相应类型进行强转
     */
    fun init(context: Context, type: Int = MeiTuan, data: Any):ShareViewManager {
        L.i("开始选择相应VIew")
        shareView = when (type) {
            MeiTuan -> MeiTuanShareAdView(context, data as String)
            else -> {
                MeiTuanShareAdView(context, data as String)
            }
        }
        shareView.onPicMakeListener ={view, bitmap ->
            L.i("回调到管理器")
            Observable.just(1)
                    .subscribeOn(AndroidSchedulers.mainThread())
                    .subscribe { c: Int? ->
                        onPicMakeListener(view,bitmap)
                    }

        }
        shareView.initView()
        return this
    }
}